#!bin/bash
# Backup Picraft minecraft server to remote places via sftp
# Auto pack server, compress it via 7z
# When finished, connect to remote file server
# sftp info :
# dogthenas.local or 10.0.0.101
# Account : walker
# Password: ------------------
# Dir /server_backup/picraft_mcserver

# Connecting backup server

# get date time
Rd=`date +%Y%m%d`

# Get time via founction
St() {
  date +"%Y-%m-%d %H:%M:%S"
}


# Link colour table
source /home/pi/scripts/colourtable.sh


clear
echo ""
echo -e "====${GREEN}Picraft Starter${NC}================================================"
echo ""
echo "                         PICRAFT BACKUP                            "
echo ""
echo "==================================================================="
echo ""
# Log event
echo "[$(St)] 7z: file compressing started." >> /home/pi/scripts/log.txt
# End Log event 

echo "Starting time:"
echo $(St)
echo ""
sleep 1

echo "Getting server files..."
sleep 1

echo ""
echo -e "====${GREEN}7z${NC}============================================================="
echo ""

7z a -t7z -m0=lzma2 -mx=9 -md=32m -ms=on -mhe=on /home/pi/backup/picraft_$Rd.7z /home/pi/server

echo ""
echo "==================================================================="
sleep 1

echo ""
echo -e "====${GREEN}7z${NC}============================================================="
echo ""
echo "                    Files has been packed!                        "
echo ""
echo "==================================================================="
sleep 1
echo "Getting relate backup to Dogthenas"
echo ""
echo -e "====${GREEN}SFTP${NC}==========================================================="
echo ""
# Log event
echo "[$(St)] 7z: file packed." >> /home/pi/scripts/log.txt
# End Log event 

bash /home/pi/scripts/sftp.sh

echo ""
echo "File has been send to targe path."
echo "==================================================================="
echo ""

sleep 1

echo -e "====${GREEN}Picraft Starter${NC}================================================"
echo ""
echo "                              Done!                                "
echo ""
echo "==================================================================="